#pragma once
#include <iostream>
#include <string>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>

/**
 * 封装address IP and port
 * 
 */
class InetAddress{
public:
    InetAddress(){}
    explicit InetAddress(uint16_t port, std::string ip = "127.0.0.1");
    explicit InetAddress(sockaddr_in addr):addr_(addr){}

    std::string toIp() const;
    std::string toIpPort() const;
    uint16_t toPort() const;

    const sockaddr_in* getSockAddr() const {return &addr_;}
    void setSockAddr(sockaddr_in& addr) {addr_ = addr;}
private:
    struct sockaddr_in addr_;
};